package com.manor.paradise.adapter

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.drawable.DrawableCreator
import com.manor.common.utils.DpUtil
import com.blankj.utilcode.util.SpanUtils
import com.manor.paradise.R
import com.manor.paradise.bean.ReikindexBean
import com.manor.common.custom.BorderRoundTransformation

class ReikIndexAdapter(layoutResId: Int, data: MutableList<ReikindexBean.RecordsBean>?) : BaseQuickAdapter<ReikindexBean.RecordsBean, BaseViewHolder>
(layoutResId, data) {

    override fun convert(holder: BaseViewHolder, item: ReikindexBean.RecordsBean) {

        val req = RequestOptions()
                .transform(
                        CenterCrop(),
                        CircleCrop(),
                        BorderRoundTransformation(context,
                                holder.getView<ImageView>(R.id.im_av).width / 2,
                                0,
                                5,
                                Color.WHITE,
                                4)
                )

        Glide.with(context)
                .load(item.avatar)
                .apply(req)
                .into(holder.getView(R.id.im_av))

        holder.setText(R.id.tv_id, "淘米号：" + item.serialNo)
                .setText(R.id.tv_rtiem, "注册时间：" + item.createTime)

        setSpan(holder.getView(R.id.tv_anima), item.anima.toString(), "个人活跃")
        setSpan(holder.getView(R.id.tv_tribal), item.teamLiveness.toString(), "团队活跃度")
        setSpan(holder.getView(R.id.tv_subordinates), item.lowerCountString , "已孵/已邀")

        setLevel(item.star, holder.getView(R.id.tvLevel), holder.getView(R.id.ivLevel), holder.getView(R.id.bl_lay))



    }

    private fun setSpan(tv: TextView, content: String, title :String){
        SpanUtils.with(tv)
                .appendLine(content)
                .append(title)
                .setForegroundColor(Color.parseColor("#66ffffff"))
                .setFontSize(12, true)
                .create()
    }

    private fun setLevel(star: String, tv: TextView, img: ImageView, lay: LinearLayout){
        when (star) {
            "0" -> {
                tv.text = "一星农场主"
                img.setBackgroundResource(R.mipmap.pic_y_jz0)
                lay.background = getLevelDrawable()
            }
            "1" -> {
                tv.text = "二星农场主"
                img.setBackgroundResource(R.mipmap.pic_y_jz1)
                lay.background = getLevelDrawable()
            }
            "2" -> {
                tv.text = "三星农场主"
                img.setBackgroundResource(R.mipmap.pic_y_jz2)
                lay.background = getLevelDrawable()
            }
            "3" -> {
                tv.text = "四星农场主"
                img.setBackgroundResource(R.mipmap.pic_y_jz3)
                lay.background = getLevelDrawable()
            }
//            "4" -> {
//                tv.text = "璀璨钻石"
//                img.setBackgroundResource(R.mipmap.pic_y_jz4)
//                lay.background = getLevelDrawable()
//            }
            else -> {
                tv.text = "一星农场主"
                img.setBackgroundResource(R.mipmap.pic_n_jz1)
                lay.background = DrawableCreator.Builder()
                        .setCornersRadius(DpUtil.dp2px(8).toFloat())
                        .setSolidColor(Color.parseColor("#FF484747"))
                        .build()
            }
        }
    }

    private fun getLevelDrawable(): Drawable =
            DrawableCreator.Builder()
                    .setCornersRadius(DpUtil.dp2px(8).toFloat())
                    .setSolidColor(Color.parseColor("#FF3F89FF"))
                    .build()


}